//
//  LGCancerPatientBasicHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/19.
//  癌症 - 基本信息

#import "LGCancerPatientBasicHeader.h"

@interface LGCancerPatientBasicHeader()
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UILabel *diagnoseLabel;
/**   */
@property (nonatomic , strong)UILabel *stageLabel;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;

@end

@implementation LGCancerPatientBasicHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:LGNSString(dataDic[@"avatar_url"])]];
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@",dataDic[@"gender"],dataDic[@"age"]];
}

//诊断病症
-(void)setDiagnose:(NSString *)diagnose{
    _diagnose = diagnose;
    CGFloat diagnoseW = (diagnose.length>0)?[diagnose textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT]+viewPix(12):0;
    CGFloat dianoseL = (diagnose.length>0)?viewPix(8):0;
    self.diagnoseLabel.text = diagnose;
    self.diagnoseLabel.hidden = (diagnose.length>0)?NO:YES;
    [self.diagnoseLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(dianoseL);
        make.width.equalTo(@(diagnoseW));
    }];
}

//临床分期
-(void)setBlfx:(NSString *)blfx{
    _blfx = blfx;
    CGFloat nameW = [self.nameLabel.text textWidthWithFont:LGFontWeight(18, UIFontWeightMedium) maxHeight:MAXFLOAT]+viewPix(7);
    CGFloat ageW = [self.ageLabel.text textWidthWithFont:LGFont(14) maxHeight:MAXFLOAT]+viewPix(8);
    CGFloat diagnoseW = (self.diagnose.length>0)?[self.diagnose textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT]+viewPix(20):0;
    CGFloat left = viewPix(92)+nameW+ageW+diagnoseW;
    CGFloat stageW = (blfx.length>0)?[blfx textWidthWithFont:LGFontWeight(12, UIFontWeightMedium) maxHeight:MAXFLOAT]+viewPix(12):0;
    stageW = ((left+stageW)>Screen_W)?(Screen_W-left-viewPix(10)):stageW;
    self.stageLabel.text = blfx;
    self.stageLabel.hidden = (blfx.length>0)?NO:YES;
    [self.stageLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(stageW));
    }];
}

-(void)setTime:(NSString *)time{
    _time = time;
    self.timeLabel.text = [NSString stringWithFormat:@"确诊时间  %@",time];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    [self addSubview:self.headPic];
    [self addSubview:self.nameLabel];
    [self addSubview:self.ageLabel];
    [self addSubview:self.diagnoseLabel];
    [self addSubview:self.stageLabel];
    [self addSubview:self.timeLabel];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(12));
        make.top.equalTo(self.headPic).offset(viewPix(10));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(7));
        make.centerY.equalTo(self.nameLabel);
    }];
    [self.diagnoseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.ageLabel.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(0));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.stageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.diagnoseLabel.mas_right).offset(viewPix(6));
//        make.right.greaterThanOrEqualTo(self).offset(-viewPix(5));
        make.centerY.equalTo(self.nameLabel);
        make.width.equalTo(@(0));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.nameLabel);
    }];
    
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(12), viewPix(64), viewPix(64))];
        [_headPic addBorder:@"#FFFFFF" lineWidth:2 cornerRidus:viewPix(32)];
        _headPic.cornerRidus = viewPix(32);
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        [_nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UILabel *)diagnoseLabel{
    if(!_diagnoseLabel){
        _diagnoseLabel = [UILabel lableWithText:@"" colorString:@"#5E8EF5" textFont:LGFontWeight(12, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _diagnoseLabel.backgroundColor = [UIColor whiteColor];
        _diagnoseLabel.cornerRidus = 3;
    }
    return _diagnoseLabel;
}

-(UILabel *)stageLabel{
    if(!_stageLabel){
        _stageLabel = [UILabel lableWithText:@"" colorString:@"#5E8EF5" textFont:LGFontWeight(12, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _stageLabel.backgroundColor = [UIColor whiteColor];
        _stageLabel.cornerRidus = 3;
    }
    return _stageLabel;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(15) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}



@end
